package com.wzl.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzl.backend.common.Result;
import com.wzl.backend.pojo.Word;
import com.wzl.backend.service.WordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/word")
@Api(tags = "单词接口")
@CrossOrigin("*")
public class WordController {

    @Autowired
    private WordService wordService;

    @GetMapping("getAll")
    @ApiOperation("获取所有单词")
    public Result getAll() {
        return Result.ok(wordService.list());
    }

    @PostMapping("insert")
    @ApiOperation("添加单词")
    public Result insert(Word word) {
        wordService.save(word);
        return Result.ok();
    }

    @GetMapping("/{page}/{limit}")
    public Result getPage(@PathVariable int limit, @PathVariable int page){
        Page<Word> page1 = new Page<>(page , limit);
        Page<Word> page2 = wordService.page(page1);
        return Result.ok(page2);
    }

    @GetMapping("count")
    public Result getCount() {
        return Result.ok(wordService.count());
    }

}
